package com.zjmzxfzhl.modules.app.service.impl;

import com.zjmzxfzhl.modules.app.entity.AppProdTag;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zjmzxfzhl.common.core.base.BaseServiceImpl;
import com.zjmzxfzhl.modules.app.entity.AppProdTag;
import com.zjmzxfzhl.modules.app.mapper.AppProdTagMapper;
import com.zjmzxfzhl.modules.app.service.AppProdTagService;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Service
 * 
 * @author 张森荣
 */
@Service
public class AppProdTagServiceImpl extends BaseServiceImpl<AppProdTagMapper, AppProdTag>
        implements AppProdTagService {
    @Override
    public IPage<AppProdTag> list(IPage<AppProdTag> page, AppProdTag appProdTag) {
        return page.setRecords(baseMapper.list(page, appProdTag));
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveAppProdTag(AppProdTag appProdTag) {
        List<AppProdTag> appProdTagList=baseMapper.list(null, appProdTag);
        if(appProdTagList.size()>0){
            return false;
        }
        Boolean result=this.save(appProdTag);
        return result;
    }

    /**
     * 新增项目，自动计算机构级别、机构级次码、是否叶子
     *
     * @param appProdTag
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean relationDel(AppProdTag appProdTag) {
        Map<String, Object> columnMap=new HashMap<>();
        columnMap.put("PROD_ID",appProdTag.getProdId());
        columnMap.put("TAG_ID",appProdTag.getTagId());
        Boolean result=this.removeByMap(columnMap);
        return result;
    }
}
